package worker

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

type Config struct {
	ApiPort            int      `json:"port"`
	ApiReadTimeOut     int      `json:"readTimeOut"`
	ApiWriteTimeOut    int      `json:"writeTimeOut"`
	EtcdEndPoints      []string `json:"etcdEndPoints"`
	EtcdDialTimeOut    int      `json:"etcdDialTimeOut"`
	WebRoot            string   `json:"webroot"`
	MongoPath          string   `json:"mongoPath"`
	LogMaxSize         int      `json:"logMaxSize"`
	LogAutoCommitTimer int      `json:"LogAutoCommitTime"`
}

var (
	G_config *Config
)

func InitConfig(path string) (err error) {
	var (
		configByte []byte
		config     Config
	)
	if configByte, err = ioutil.ReadFile(path); err != nil {
		return
	}
	if err = json.Unmarshal(configByte, &config); err != nil {
		return
	}
	G_config = &config

	fmt.Println("初始化配置完成")
	return
}
